﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
    <title>我的信息</title>
    <link href="css/pages.css" rel="stylesheet" />
    <link href="css/MyMessage.css" rel="stylesheet" />
    <script src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="Scripts/wechatsdk/jssdk.js"></script>
    <SCRIPT type="text/javascript">
    

	var myname,contact,roomname,roomaddress,QRimg,mynumb;
	var ifleader;
	var member_row,member_new;

	var url = location.href.split('#')[0];
	    
	var start = url.indexOf("code=");
	    
	var end = url.indexOf("&");
	
	var code = url.substring(start+5,end);
	
	 $.ajax({
		    async: false,
			cache:false,
	    	type: 'POST',
	    	data:{
	    		code:code
	    	},
	    	url: "WeChatAction_mymessage.action",
	    	dataType:"json",
	    	success: function (data) {
	    		msg = eval("(" + data + ")");
	    		if(msg.msg==true){
	    			mynumb=msg.mynumb;
	    			myname=msg.people;
	    			contact = msg.phone;
	    			ifleader = msg.ifleader;
	    			roomname = msg.pointname;
	    			roomaddress = msg.addr;
	    			leader_name = msg.leadername;
	    			QRimg = msg.qrimg;
	    		} else if(msg.msg==false){
	    			alert("对不起，你还没有注册，请注册后再试！");
	    		}
	  	  },
	 	   error: function () {
	  	      alert("出现异常！！");
	  		 }
		})
	
	
	
	$(function() {
	    /* alert(location.href.split('#')[0]); */

		if(ifleader==2||ifleader==4){
			member();
			$(function(){
	            $("#photobox").append("<img id='QRimg' style='width:100%;height:100%' src='http://wechatest00001.51vip.biz/math_app/"+QRimg+"' alt='用户组二维码' />");
			});
		} else if(ifleader==3||ifleader==1){
			$(function(){
				$("#photobox").append("<span style='line-height:11rem'>正在审核中。。。。</span>");
			//	member();
			});
		} else if(ifleader==0){
			$(function(){
				$("#photobox").append("<input class='erweima' onclick='scanQRCode()' type='button' value='扫一扫'/>");
				$("#photobox").listview("refresh");
				//$("#photobox").trigger("<input class='erweima' onclick='scanQRCode()' type='button' value='扫一扫'/>");
			});
		}
		
		mymessages();
		
       // $(".photobox").children(".erweima").css("display", "block");
    });
	
		function mymessages(){
			$("#myname").val(myname);
			$("#contact").val(contact);
			$("#roomname").val(roomname);
			$("#roomaddress").val(roomaddress);
			$("#leader_name").val(leader_name);
	//		$("#QRimg").attr("src","http://wechatest00001.51vip.biz/"+QRimg);
		};
		

		function member(){
		$.ajax({
		    async: false,
			cache:false,
	    	type: 'POST',
	    	url: "WeChatAction_memberrow.action",
	    	/* data{
	    		code:code
	    	}, */
	    	dataType:"json",
	    	success: function (data) {
	    	if(data!=null){
	    		$.each(data, function (index, item) {  
	                //循环获取数据    
	                var name = data[index].name;
	                var id = data[index].numb;
	                /* $(function(){ */
	                    $("#member_row").append("<li class='member_name' id='"+id+"'>"+"<input value='"+name+"' readonly /><span class='icon_del'>-</span></li>");
	    			/* }); */
	            }); 
	    	}
	    		
	  	  },
	 	   error: function () {
	  	      alert("出现异常！！");
	  		 }
		});
		
		
		 $.ajax({
		    async: false,
			cache:false,
	    	type: 'POST',
	    	url: "WeChatAction_membernew.action",
	    	dataType:"json",
	    	success: function (data) {
	    	if(data!=null){
	    		$.each(data, function (index, item) {  
	                //循环获取数据   
	                var name = data[index].name;
	                var id = data[index].numb;
	               /*  $(function(){ */
	                    $("#member_news").append("<li class='member_name' id='"+id+"'>"+"<input value='"+name+"' readonly /><span class='icon_add'>+</span><span class='icon_del'>-</span></li>");
	    			/* }); */
	            }); 
	    	}
	    		
	  	  },
	 	   error: function () {
	  	      alert("出现异常！！");
	  		 }
		});
	}
    
    </SCRIPT>
    
</head>
<body>
    <div class="photobox" id="photobox">
       <!--  <img id="QRimg" style="width:100%;height:100%" src="" alt="用户组二维码" />
        <input class="erweima" onclick="scanQRCode()" type="button" value="扫一扫"/> -->
    </div>
    <div class="group_message">
        <div class="myinfo_row">
            <span class="rowtitle">姓名：</span><input name="myname" readonly id="myname" placeholder="姓名" />
           <!--  <span id="myname" class="rowtitle"></span> -->
        </div>
        <div class="myinfo_row">
            <span class="rowtitle">联系方式：</span><input name="contact" readonly id="contact" placeholder="联系方式" />
           <!--  <span id="contact" class="rowtitle"></span> -->
        </div>
        <div class="myinfo_row">
            <span class="rowtitle">办公室名称：</span><input name="roomname" readonly id="roomname" placeholder="我所在的消控室名称" />
           <!--  <span id="roomname" class="rowtitle"></span> -->
        </div>
        <div class="myinfo_row" style="border:none;">
            <span class="rowtitle">办公室地址：</span><input name="roomaddress" readonly id="roomaddress" placeholder="我所在的消控室地址" />
           <!--  <span id="roomaddress" class="rowtitle"></span> -->
        </div>
    </div>
    <span class="leader">组长</span>
    <div class="group">
        <input readonly class="leader_name" id="leader_name" value="" placeholder="组长姓名" />
    </div>

    <span class="member">组员</span><span class="member_change">编辑</span>
    <div class="group" id="member_old">
        <div class="group_member">
            <ul class="member_row" id="member_row">
                <!-- <li class="member_name"><input type="hidden" value="dd"/><input value="张飞" alt="156" readonly /><span class="icon_del">-</span></li> -->
            </ul>
        </div>
    </div>
    <span class="member">申请</span><span class="member_check">审核</span>
    <div class="group" id="member_new">
        <div class="group_member">
            <ul class="member_row" id="member_news">
                <!-- <li class="member_name"><input value="赵云" readonly /><span class="icon_add">+</span><span class="icon_del">-</span></li> -->
            </ul>
        </div>
    </div>
    
    
    <!--微信sdk接口js-->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>

	var timestamp,nonceStr,signature,appid;
	var result;
	$.ajax({
 	   async: false,
		cache:false,
		type: 'POST',
		url: "WeChatAction_webweixin.action",
		data:{
			url:encodeURIComponent(location.href.split('#')[0]),
		//	url:location.href.split('#')[0]
		},
		dataType:"json",
		success: function (data) {
			
			msg = eval("(" + data + ")");
			if(msg.msg==1){
				timestamp = msg.timestamp;
				nonceStr = msg.nonceStr;
				signature = msg.signature;
				appid = msg.appId;
			} else {
				
			}
		  },
		   error: function () {
		      alert("1111出现异常！！");
			 }
	});

    wx.config({
        debug: false,
        appId: appid,
        timestamp: timestamp,
        nonceStr: nonceStr,
        signature: signature,
        jsApiList: [
          'checkJsApi',
 			'scanQRCode'
        ]
    });
	
	wx.error(function(res){
		alert("出错了！"+res.errMsg);
	});
	function scanQRCode(){
		wx.ready(function(){
			wx.checkJsApi({
				jsApiList:['scanQRCode'],
				success:function(res){
					
				}
			});
			
			//扫描二维码
			wx.scanQRCode({
				needResult:1,
				scanType:["barCode"],
				success:function(res) {
					result = res.resultStr;
					join();
				//	alert("扫描常规：：扫描码="+result);
				}
			});
			
		});
		
		function join(){
			$.ajax({
			 	   async: false,
					cache:false,
					type: 'POST',
					url: "PeopleAction_join.action",
					data:{
						numb:mynumb,
						pointid:result
					},
					dataType:"json",
					success: function (data) {
						msg = eval("(" + data + ")");
						if(msg.msg==1){
							alert("申请成功！等待验证。。");
							window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3542023ee690ee77&redirect_uri=http%3A%2F%2Fwechatest00001.51vip.biz%2Fmath_app%2FWeChat%2FMyMessage.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
						} else {
							alert("申请失败！");
						}
					  },
					   error: function () {
					      alert("出现异常！！");
						 }
				});

		}
	
	};
	
</script>
    <script src="Scripts/wechatsdk/zepto.min.js"></script>
    
    
</body>
</html>
<script>

    $(function () {
        changemember();
        deleteli();
        changememberB();
        addli();
    });
    
    function changemember() {
        $(".member_change").click(function () {
            //alert("shneme ");
            var select1 = $("#member_old").find(".member_name").find(".icon_del");
            if (select1.hasClass("icon_del_toggel")) {
                select1.removeClass("icon_del_toggel");
                $(".member_change").css({ "color": "#fff", "background-color": "#4097ee" });
            } else {
                select1.addClass("icon_del_toggel");
                $(".member_change").css({ "color": "#4097ee", "background-color": "#fff" });
            }
        });
    };
    
    function deleteli() {
        $("#member_old").find(".member_name").delegate(".icon_del", "click", function () {
        	var id=$(this).parent().attr("id");
        	alert('删除当前的行，且从该员工所属的组里清除此员工:'+$(this).parent().find("input").attr("value"));
        	$.ajax({
        	    async: false,
        		cache:false,
            	type: 'POST',
            	url: "PeopleAction_people_set.action",
            	data:{
            		numb:id,
            		mynumb:mynumb,
            		state:1
            	},
            	dataType:"json",
            	success: function (data) {
            		msg = eval("(" + data + ")");
            		if(msg.msg==1){
            			alert("删除成功！");
            			window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3542023ee690ee77&redirect_uri=http%3A%2F%2Fwechatest00001.51vip.biz%2Fmath_app%2FWeChat%2FMyMessage.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
            		//	window.location.reload(force);
            		} else if(msg.msg==2){
            			alert("对不起，你还没有注册，请注册后再试！");
            		} else if(msg.msg==3){
            			alert("对不起，你不是组长，无法执行此操作！");
            		}
          	  },
         	   error: function () {
          	      alert("出现异常！！");
          		 }
        	})
        	
        //	alert(id);
            
        });
    }
    function changememberB() {
        $(".member_check").click(function () {
            //alert("shneme ");
            var select1 = $("#member_new").find(".member_name").find(".icon_del");
            var select2 = $("#member_new").find(".member_name").find(".icon_add");
            if (select1.hasClass("icon_del_toggel")) {
                $(".member_check").css({ "color": "#fff", "background-color": "#4097ee" });
                select1.removeClass("icon_del_toggel");
                select2.removeClass("icon_add_toggel");
            } else {
                $(".member_check").css({ "color": "#4097ee", "background-color": "#fff" });
                select1.addClass("icon_del_toggel");
                select2.addClass("icon_add_toggel");
            }
        });
    };
    function addli() {
        $("#member_new").find(".member_name").delegate(".icon_del", "click", function () {
        	var id=$(this).parent().attr("id");
        	alert('删除当前的行申请，不同意员工' + $(this).parent().text()+"加入");
        	$.ajax({
        	    async: false,
        		cache:false,
            	type: 'POST',
            	url: "PeopleAction_people_set.action",
            	data:{
            		numb:id,
            		mynumb:mynumb,
            		state:1
            	},
            	dataType:"json",
            	success: function (data) {
            		msg = eval("(" + data + ")");
            		if(msg.msg==1){
            			alert("删除成功！");
            			window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3542023ee690ee77&redirect_uri=http%3A%2F%2Fwechatest00001.51vip.biz%2Fmath_app%2FWeChat%2FMyMessage.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
            		//	window.location.reload(force);
            		} else if(msg.msg==2){
            			alert("对不起，你还没有注册，请注册后再试！");
            		} else if(msg.msg==3){
            			alert("对不起，你不是组长，无法执行此操作！");
            		}
          	  },
         	   error: function () {
          	      alert("出现异常！！");
          		 }
        	})

        });
        $("#member_new").find(".member_name").delegate(".icon_add", "click", function () {
        	var id=$(this).parent().attr("id");
            alert('同意' + $(this).parent().text() + "加入");
            
            $.ajax({
        	    async: false,
        		cache:false,
            	type: 'POST',
            	url: "PeopleAction_people_set.action",
            	data:{
            		numb:id,
            		mynumb:mynumb,
            		state:0
            	},
            	dataType:"json",
            	success: function (data) {
            		msg = eval("(" + data + ")");
            		if(msg.msg==1){
            			alert("加入成功！");
            			window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3542023ee690ee77&redirect_uri=http%3A%2F%2Fwechatest00001.51vip.biz%2Fmath_app%2FWeChat%2FMyMessage.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
            		//	window.location.reload(force);
            		} else if(msg.msg==2){
            			alert("对不起，你还没有注册，请注册后再试！");
            		} else if(msg.msg==3){
            			alert("对不起，你不是组长，无法执行此操作！");
            		}
          	  },
         	   error: function () {
          	      alert("出现异常！！");
          		 }
        	})
        });
    }
</script>